package com.bigdata.warehouse.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ClickhouseUtil {
    private static Connection connection;
    public static Connection getConn(String host,int port,String database) throws ClassNotFoundException, SQLException {
        Class.forName("ru.yandex.clickhouse.ClickHouseDriver");
        String address = "jdbc:clickhouse://"+host+":"+port+"/"+database;
        connection= DriverManager.getConnection(address,"default","123456");
        return connection;
    }
    public static Connection getConn(String host,int port) throws SQLException, ClassNotFoundException {
        return getConn(host,port,"default");
    }
    public static Connection getConn() throws SQLException, ClassNotFoundException {
        return getConn("slave3",8123);
    }
    public void close() throws SQLException {
        connection.close();
    }
}
